
clear 
set scheme lean2, permanent
global pm = char(177) 
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "robustnessexperiment3.dta", clear

cd "$path_output"
 
drop if t15med==1

gen cons=1

gen anyinfo_noprior=anyinfo*noprior

gen prior_high_conf=(prior_conf>3)
gen anyinfo_prior_high_conf=anyinfo*prior_high_conf

qui sum prior_conf
gen z_prior_conf=((prior_conf-r(mean))/r(sd))
gen z_posterior_conf=((posterior_conf-r(mean))/r(sd)) // note: also standardize posterior confidence by mean and SD of prior confidence to make this meaningful.

gen D_z_conf=z_posterior_conf-z_prior_conf

gen shock=signal-prior // this is the general shock variable.
replace shock=0 if control_prior==1|control_noprior==1|tanchor==1

gen shock_prior_high_conf=shock*prior_high_conf
gen prior_prior_high_conf=prior*prior_high_conf

gen shock_t15avg=shock*t15avg
gen shock_t30=shock*t30

gen shock_placebo=shock if t5==1|control_prior==1 // this is the shock variable for the placebo analysis.
replace shock_placebo=5-prior if tanchor==1
gen shock_placebo_tanchor=shock_placebo*tanchor

gen upd_shock=updating/shock
winsor upd_shock, p(.05) gen(upd_shock_w05)
gen log_upd_shock=log(updating/shock)

global controls female atleast_bachelor age agesq log_inc midwest south west inc_NR

loc experiments "D_z_conf D_z_conf D_z_conf D_z_conf D_z_conf"

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {
    loc ++columns
    qui eststo col`columns': reg x y
}

restore
loc colnum = 1
loc colnames ""

    reg D_z_conf anyinfo z_prior_conf prior $controls, r, if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    sigstar anyinfo, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col1
    estadd loc thisstat3 = "`r(sestar)'": col1
	qui sum D_z_conf if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    estadd loc thisstat29 = r(N): col1
	estadd loc thisstat31 = "T5,T15": col1
	estadd loc thisstat32 = "T30,TA,C": col1

    reg D_z_conf anyinfo anyinfo_prior_high_conf prior_high_conf z_prior_conf prior $controls, r, if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    sigstar anyinfo, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col2
    estadd loc thisstat3 = "`r(sestar)'": col2
	sigstar anyinfo_prior_high_conf, prec(3)
    estadd loc thisstat5 = "`r(bstar)'": col2
    estadd loc thisstat6 = "`r(sestar)'": col2
	sigstar prior_high_conf, prec(3)
    estadd loc thisstat8 = "`r(bstar)'": col2
    estadd loc thisstat9 = "`r(sestar)'": col2
	qui sum D_z_conf if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    estadd loc thisstat29 = r(N): col2
	estadd loc thisstat31 = "T5,T15": col2
	estadd loc thisstat32 = "T30,TA,C": col2

	reg D_z_conf t5 t15avg t30 tanchor prior z_prior_conf $controls, r, if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    sigstar t5, prec(3)
    estadd loc thisstat11 = "`r(bstar)'": col3
    estadd loc thisstat12 = "`r(sestar)'": col3
	sigstar t15avg, prec(3)
    estadd loc thisstat14 = "`r(bstar)'": col3
    estadd loc thisstat15 = "`r(sestar)'": col3
	sigstar t30, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col3
    estadd loc thisstat18 = "`r(sestar)'": col3
	sigstar tanchor, prec(3)
    estadd loc thisstat20 = "`r(bstar)'": col3
    estadd loc thisstat21 = "`r(sestar)'": col3
	qui sum D_z_conf if t15avg==1|t30==1|t5==1|control_prior==1|tanchor==1
    estadd loc thisstat29 = r(N): col3
	estadd loc thisstat31 = "T5,T15": col3
	estadd loc thisstat32 = "T30,TA,C": col3

	reg D_z_conf log_upd_shock prior z_prior_conf $controls if t15avg==1|t30==1|t5==1
	sigstar log_upd_shock, prec(3)
    estadd loc thisstat23 = "`r(bstar)'": col4
    estadd loc thisstat24 = "`r(sestar)'": col4
	qui sum D_z_conf if (t15avg==1|t30==1|t5==1) & log_upd_shock!=.
    estadd loc thisstat29 = r(N): col4
	estadd loc thisstat31 = "T5,T15": col4
	estadd loc thisstat32 = "T30": col4
	
	reg D_z_conf upd_shock_w05 prior z_prior_conf $controls if t15avg==1|t30==1|t5==1
	sigstar upd_shock_w05, prec(3)
    estadd loc thisstat26 = "`r(bstar)'": col5
    estadd loc thisstat27 = "`r(sestar)'": col5
	qui sum D_z_conf if (t15avg==1|t30==1|t5==1) & upd_shock_w05!=.
    estadd loc thisstat29 = r(N): col5
	estadd loc thisstat31 = "T5,T15": col5
	estadd loc thisstat32 = "T30": col5

	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

loc rowlabels " " " "Any info" " " " " "Any info $\times$" "Confident" " " "Confident" " " " " "T5" " " " " " T15" " " " " "T30" " " " " "TAnchor" " " " " "$\log(\text{Updating/}$" "$\text{Shock})$" " " "$\text{Updating/}$" "$\text{Shock}$" " " "Observations" " " "Sample" " " " "   "


loc rowstats ""

forval i = 1/32 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "D_conf_RRpilot.tex", replace cells(none) booktabs nonotes nomtitles /*nonum*/ compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
      mgroups("$\Delta$ Confidence" , pattern(1 0 0 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

eststo clear	




